﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Kokomo.Mirror.CliMetadata.Signatures;

namespace Kokomo.Mirror.CliMetadata
{
	class SignatureRefPropertyDescriptor : MetadataRowPropertyDescriptor
	{
		public SignatureRefPropertyDescriptor(
			PropertyDescriptor baseDescriptor,
			MetadataContainer container
			)
			: base(baseDescriptor, container)
		{
		}

		public override object GetValue(object component)
		{
			ICustomTypeDescriptor descriptor = component as ICustomTypeDescriptor;
			SignatureRef signatureRef = (SignatureRef)this.BaseDescriptor.GetValue(descriptor.GetPropertyOwner(this));

			byte[] data = this.Container.GetBlob(signatureRef);

			StringBuilder builder = new StringBuilder(data.Length * 2);
			for (int i = 0; i < data.Length; i++)
			{
				byte b = data[i];
				builder.Append(b.ToString("X2"));
			}

			string str = builder.ToString();
			return str;

			//Signature signature = this.Container.GetSignature(signatureRef);
			//return signature;
		}

		public override Type PropertyType
		{
			//get { return typeof(Signature); }
			get { return typeof(string); }
		}
	}
}
